package com.example.controller;

import com.example.pojo.*;
import com.example.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {


    @Autowired
    private ClazzService clazzService;


    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除班级信息:{}", id);
        clazzService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result insert(@RequestBody Clazz clazz) {
        log.info("添加班级信息");
        clazzService.insert(clazz);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result getInfoByID(@PathVariable Integer id) {
        log.info("根据id查询班级:{}", id);
        Clazz clazz = clazzService.getInfoByID(id);
        return Result.success(clazz);
    }


    @PutMapping()
    public Result update(@RequestBody Clazz clazz) {
        log.info("修改班级信息:{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }


    //条件分页查询
    @GetMapping()
    public Result list(ClazzQueryParam clazzQueryParam) {
        log.info("班级条件分页查询:");
        PageResult<Clazz> clazzResult = clazzService.list(clazzQueryParam);
        return Result.success(clazzResult);

    }

}
